const onvif = require('node-onvif');
module.exports = {
    // 连接摄像头，并初始化
    conn: function (config) {
        return new Promise((resolve, reject) => {
            let device = null;
            try {
                device = new onvif.OnvifDevice(config);
                device.init().then((info) => {
                    resolve({
                        type: 'success',
                        message: '摄像头连接成功',
                        device: device,
                        base: require('./base')(device),
                        control: require('./control')(device),
                    })
                }).catch((error) => {
                    reject({ type: 'error', message: error.message })
                })
            } catch (error) {
                reject({ type: 'error', message: error.message })
            }
        })
    },
}